a = int(input())
q = str(a)
g = 0
s = 0
d = 0
f = 0
z = 0
ty = 0
ad = 0
bn = 0
we = 0
if len(q) != 4:
    print(0)
    
else:
    
    n1 = int(q[0])
    n2 = int(q[1])
    n3 = int(q[2])
    n4 = int(q[3])
    for k in range(2, int(q[0] + q[1] + q[2] + q[3])):
        if int(q[0] + q[1] + q[2] + q[3]) % k == 0:
            g +=1
    if  g == 0:
        ry = int(q[0] + q[1] + q[2] + q[3])
    else:
        ry = 0
               

    for wr in range(2, int(q[0])):
        if int(q[0]) % wr == 0:
            we += 1
    if we == 0:
        gh = int(q[0])
    else:
        gh = 0

    for i in range(2, int(q[0]+q[1])):
        if int(q[0]+q[1]) % i ==  0:
            s   +=1
    if s == 0:
        e = int(q[0]+q[1])
    else:
        e = 0
    

    
    for t in range(2, n2):
        if n2 % t  == 0:
            d += 1
    if d == 0:
        y = n2
    else:
        y = 0
    for m in range(2, int(q[1] + q[2])):
        if int(q[1] + q[2]) % m == 0:
            f   += 1
    if f == 0:
        g = int(q[1] + q[2])
    else:
        g = 0


    for u in range(2, n3):
        if n3 % u == 0:
            z += 1
    if z == 0:
        rt = n3
    else:
        rt = 0
    for kl in range(2, int(q[2] + q[3])):
        if int(q[2] + q[3]) % kl == 0:
            ty += 1
    if ty == 0:
        io = int(q[2] + q[3])
    else:
        io = 0
            
        
    for j in range(2, int(q[0] + q[1] + q[2])):
        if int(q[0] + q[1] + q[2]) % j == 0:
            ad += 1
    if ad == 0:
        df = int(q[0] + q[1] + q[2])
    else:
        df = 0


    for ti in range(2, int(q[1] + q[2] + q[3])):
        if int(q[1] + q[2] + q[3]) % ti == 0:
            bn += 1
    if bn == 0:
        rf = int(q[1] + q[2] + q[3])
    else:
        rf = 0


    print(max(ry, gh, e, y, g, rt, io, df, rf))
        



    
